USE Liberty
GO
-- ------------------------------------------------------------------------------------------------
-- Users create table script
-- ------------------------------------------------------------------------------------------------
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating Users table...'
GO

IF OBJECT_ID( 'Users' ) IS NULL
BEGIN
CREATE TABLE dbo.Users 
	(OID				bigint		IDENTITY(1, 1)	NOT NULL
	,GUID				varchar(64)					NOT NULL 
		CONSTRAINT DFLT_Users_GUID DEFAULT NEWID()
	,FullName			varchar(128)				NOT NULL
	,UPN				varchar(128)				NOT NULL
	,LastSignedIn		datetime						NULL
	,UpdatedDate		datetime					NOT NULL
		CONSTRAINT DFLT_Users_UpdatedDate DEFAULT GETDATE()
	,CreatedDate		datetime					NOT NULL
		CONSTRAINT DFLT_Users_CreatedDate DEFAULT GETDATE()

	,CONSTRAINT PK_Users PRIMARY KEY (OID)

	,CONSTRAINT UIX_Users_GUID UNIQUE(GUID)

	,CONSTRAINT UIX_Users_UPN UNIQUE (UPN)
	)
	PRINT 'Users table has been created...'
END 
ELSE
BEGIN
	PRINT 'Users table already exists'
END
GO
